package com.muxue.module.ai.controller.chat;


import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "管理后台 - 聊天消息")
@RestController
@RequestMapping("/ai/chat/message")
@Slf4j
public class AiChatMessageController {

//    @Resource
//    private AiChatMessageService chatMessageService;
//    @Resource
//    private AiChatConversationService chatConversationService;
//    @Resource
//    private AiChatRoleService chatRoleService;
//
//    @Operation(summary = "发送消息（段式）", description = "一次性返回，响应较慢")
//    @PostMapping("/send")
//    public CommonResult<AiChatMessageSendRespVO> sendMessage(@Valid @RequestBody AiChatMessageSendReqVO sendReqVO) {
//        return success(chatMessageService.sendMessage(sendReqVO, getUserId()));
//    }

//    @Operation(summary = "发送消息（流式）", description = "流式返回，响应较快")
//    @PostMapping(value = "/send-stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
//    @PermitAll // 解决 SSE 最终响应的时候，会被 Access Denied 拦截的问题
//    public Flux<CommonResult<AiChatMessageSendRespVO>> sendChatMessageStream(@Valid @RequestBody AiChatMessageSendReqVO sendReqVO) {
//        return chatMessageService.sendChatMessageStream(sendReqVO, getUserId());
//    }

//    @Operation(summary = "获得指定对话的消息列表")
//    @GetMapping("/list-by-conversation-id")
//    @Parameter(name = "conversationId", required = true, description = "对话编号", example = "1024")
//    public CommonResult<List<AiChatMessageRespVO>> getChatMessageListByConversationId(
//            @RequestParam("conversationId") Long conversationId) {
//        AiChatConversationDO conversation = chatConversationService.getChatConversation(conversationId);
//        if (conversation == null || ObjUtil.notEqual(conversation.getUserId(), getUserId())) {
//            return success(Collections.emptyList());
//        }
//        List<AiChatMessageDO> messageList = chatMessageService.getChatMessageListByConversationId(conversationId);
//        return success(BeanUtils.toBean(messageList, AiChatMessageRespVO.class));
//    }
//
//    @Operation(summary = "删除消息")
//    @DeleteMapping("/delete")
//    @Parameter(name = "id", required = true, description = "消息编号", example = "1024")
//    public CommonResult<Boolean> deleteChatMessage(@RequestParam("id") Long id) {
//        chatMessageService.deleteChatMessage(id, getUserId());
//        return success(true);
//    }
//
//    @Operation(summary = "删除指定对话的消息")
//    @DeleteMapping("/delete-by-conversation-id")
//    @Parameter(name = "conversationId", required = true, description = "对话编号", example = "1024")
//    public CommonResult<Boolean> deleteChatMessageByConversationId(@RequestParam("conversationId") Long conversationId) {
//        chatMessageService.deleteChatMessageByConversationId(conversationId, getUserId());
//        return success(true);
//    }
//
//    // ========== 对话管理 ==========
//
//    @GetMapping("/page")
//    @Operation(summary = "获得消息分页", description = "用于【对话管理】菜单")
//    @PreAuthorize("@ss.hasPermission('ai:chat-conversation:query')")
//    public CommonResult<PageResult<AiChatMessageRespVO>> getChatMessagePage(AiChatMessagePageReqVO pageReqVO) {
//        PageResult<AiChatMessageDO> PageResult = chatMessageService.getChatMessagePage(pageReqVO);
//        if (CollUtil.isEmpty(PageResult.getList())) {
//            return success(PageResult.empty());
//        }
//        // 拼接数据
//        Map<Long, AiChatRoleDO> roleMap = chatRoleService.getChatRoleMap(
//                convertSet(PageResult.getList(), AiChatMessageDO::getRoleId));
//        return success(BeanUtils.toBean(PageResult, AiChatMessageRespVO.class,
//                respVO -> MapUtils.findAndThen(roleMap, respVO.getRoleId(), role -> respVO.setRoleName(role.getName()))));
//    }
//
//    @Operation(summary = "管理员删除消息")
//    @DeleteMapping("/delete-by-admin")
//    @Parameter(name = "id", required = true, description = "消息编号", example = "1024")
//    @PreAuthorize("@ss.hasPermission('ai:chat-message:delete')")
//    public CommonResult<Boolean> deleteChatMessageByAdmin(@RequestParam("id") Long id) {
//        chatMessageService.deleteChatMessageByAdmin(id);
//        return success(true);
//    }

}
